package com.sample.springbatch.job.sample.writer;

import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.file.MultiResourceItemWriter;
import org.springframework.batch.item.file.SimpleResourceSuffixCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.PathResource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * Flat文件格式写入类  实现了分隔符格式
 * Created by zwg on 2017/8/8.
 */
@Component
public class RepayOrderMultiResourceFlatFileItemWriter<RepayOrderInfo> extends MultiResourceItemWriter {

    @Autowired
    RepayOrderFlatFileItemWriter repayOrderFlatFileItemWriter;

    public RepayOrderMultiResourceFlatFileItemWriter() {
        //setResource(new PathResource("target/data/repay-orders_multi_3.dat"));
        //每个文件多少条记录

        setItemCountLimitPerResource(1111);
        setResourceSuffixCreator(new SimpleResourceSuffixCreator());
        setSaveState(true);

    }



    @PostConstruct
    public void init(){
        setDelegate(repayOrderFlatFileItemWriter);
    }

    @Override
    public void open(ExecutionContext executionContext) {

        setResource(new PathResource("target/data/repay-orders_multi_3.dat"));
        super.open(executionContext);
    }
}
